home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / doc / python-apt / examples / deb_inspect.py < prev    next >
Encoding:
Python Source  |  2009-03-30  |  1.2 KB  |  50 lines

  1. #!/usr/bin/env python
  2. # some example for apt_inst
  3.  
  4. import apt_pkg
  5. import apt_inst
  6. import sys
  7. import os.path
  8.  
  9.  
  10. def Callback(What, Name, Link, Mode, UID, GID, Size, MTime, Major, Minor):
  11.     """ callback for debExtract """
  12.     print "%s '%s','%s',%u,%u,%u,%u,%u,%u,%u" \
  13.           % (What, Name, Link, Mode, UID, GID, Size, MTime, Major, Minor)
  14.  
  15.  
  16. if __name__ == "__main__":
  17.     if len(sys.argv) < 2:
  18.         print "need filename argumnet"
  19.         sys.exit(1)
  20.     file = sys.argv[1]
  21.  
  22.     print "Working on: %s" % file
  23.     print "Displaying data.tar.gz:"
  24.     apt_inst.debExtract(open(file), Callback, "data.tar.gz")
  25.  
  26.     print "Now extracting the control file:"
  27.     control = apt_inst.debExtractControl(open(file))
  28.     sections = apt_pkg.ParseSection(control)
  29.  
  30.     print "Maintainer is: "
  31.     print sections["Maintainer"]
  32.  
  33.     print
  34.     print "DependsOn: "
  35.     depends = sections["Depends"]
  36.     print apt_pkg.ParseDepends(depends)
  37.  
  38.  
  39.     print "extracting archive"
  40.     dir = "/tmp/deb"
  41.     os.mkdir(dir)
  42.     apt_inst.debExtractArchive(open(file), dir)
  43.  
  44.     def visit(arg, dirname, names):
  45.         print "%s/" % dirname
  46.         for file in names:
  47.             print "\t%s" % file
  48.  
  49.     os.path.walk(dir, visit, None)
  50.